﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;


namespace Common
{
    public abstract class DatabaseKoppeling
    {
        public static OracleConnection conn;


        /// <summary>DatabaseKoppeling() is de constructor class.
        /// <para> Hierin wordt de login + password en het adress van de oracle database ingevoerd.</para>
        /// </summary>
        static DatabaseKoppeling()
        {
            conn = new OracleConnection();
            String pcn = "240098";
            String pw = "2169745";
            conn.ConnectionString = "User Id=" + pcn + ";Password=" + pw + ";Data Source=" + "//webdb.hi.fontys.nl:1521/cicdb.informatica.local" + ";";
        }
        public static string[] inlogSeq(string RFID,string hwachtwoord)
        {
            OracleCommand cmd = new OracleCommand();
            cmd.Parameters.Add(new OracleParameter("RFID", RFID));
            cmd.Parameters.Add(new OracleParameter("hwachtwoord", hwachtwoord));
            cmd.CommandText = "SELECT Type FROM Persoon WHERE RFID = :RFID and wachtwoord = :hwachtwoord" ;
            cmd.Connection = conn;

            string[] data = new string[1];

            try
            {
                conn.Open();
                OracleDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {

                    data[0] = reader["TYPE"].ToString();
                }
            }
            catch (OracleException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return data;
        }       // zoekt in de database het bijbehorende wachtwoord van het gegeven RFID en returned deze

    }
}
